<%@page import="org.jackysoft.report.ProductValidation"%>
<%@ page contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ taglib  uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib  uri="http://www.springframework.org/security/tags" prefix="sec" %>
<%@ taglib  uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib  uri="http://www.joda.org/joda/time/tags" prefix="joda" %>
<!DOCTYPE html>
<html>
<head>
<base href="${base}" target="_self" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<%@ include file="../commons/headfiles-jquery.jsp" %>
<title>合同浏览</title>
</head>
<body>
<form id="dform">
<table class="table table-hover table-bordered">
  <tbody>
     <tr>
       <td>产品代码</td>
       <td>
          <input id="pdt" />
       </td>
     </tr>
     <tr>
       <td>合同号</td>
       <td>
         <select id="contracts"></select> 
       </td>
     </tr>
     <tr>
       <td>产品名称</td>
       <td>
          <span id="name"></span>
       </td>
     </tr>
     <tr>
       <td>批号</td>
       <td>
         <input id="batchName"  />
       </td>
     </tr>
     <tr>
       <td>箱数</td>
       <td>
         <input onblur="judgeNumber(this)"  id="boxes"  />
       </td>
     </tr>
     <tr>
       <td>数量[万/公斤/KG/M]</td>
       <td>
         <input onblur="judgeNumber(this)" id="value"  />
       </td>
     </tr>
  </tbody>
  
  <tfoot>
     <tr>
     <td colspan="2" class="btn-group">
       <button class="btn btn-success" type="button" onclick="addRepo()">添加出库</button>
    
       <button class="btn"  type="button"  onclick="window.close()">关闭</button>
     </td>
     </tr>
  </tfoot>
</table>
</form>
<script type="text/javascript">
var cid= '${param.cid}';
var data  ={
		contract:{
			id:'',
			name:''
		},
		product:{
			code:'',
			name:''	
		},
		boxes:0,
		batchName:'',
		value:0	
};
$(function(){
	setAutoComplete("pdt");
	$("#contracts").load('contract/contract!byclient?client.id='+cid); 
});

function addRepo(){	
	data.contract.id=$("#contracts").val();
    data.contract.name=$("#contracts option:selected").text();
	data.boxes = $("#boxes").val();
	data.batchName=$("#batchName").val();
	data.value = $("#value").val();
	var parent = window.dialogArguments; 
	parent.addLine(data);
	$("#pdt").val('');
	
}
function setAutoComplete(id) {
    var obj = $("#"+id);
	obj.autocomplete({
		minLength : 3,
		source : function(request, response) {
			var term = request.term;
			$.getJSON(
					"product/product!searchall", 
					{"term" : term}, 
					function(data) {
						response(data);
					}							
			);
		},
		focus : function(event, ui) {
			obj.val(ui.item.code);
			return false;
		},
		select : function(event, ui) {
			obj.val(ui.item.code);	
			data.product.code = ui.item.code;
			data.product.name = ui.item.name;
			$("#name").text(ui.item.name);
			return false;
		}

	})
	.data("autocomplete")._renderItem = function(ul, item) {
		return $("<li></li>").data("item.autocomplete", item).append(
				"<a>" + item.code + "|" + item.name + "</a>").appendTo(ul);
	};
}
</script>
</body>
</html>